/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.ucase.caseadditional.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.dicenum.IsConfirmEnum;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.ConvertUpMoneyUtil;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseAdditionalDataReportService;
import com.icinfo.cloud.provider.punish.common.datareport.service.impl.CaseDataReportDecisionServiceImpl;
import com.icinfo.cloud.provider.punish.csource.manage.enums.CaseSourceEnum;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.dto.CaseAdditionalRecordDto;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.dto.CasePartiesPersonInfoAddDto;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.enums.CaseAdditionalRecordCaseTypeEnums;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.enums.CaseAdditionalRecordFlowEnums;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.enums.CaseAdditionalRecordInformEnums;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.enums.SendWayEnums;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.mapper.CaseAdditionalRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.model.CaseAdditionalRecord;
import com.icinfo.cloud.provider.punish.ucase.caseadditional.service.ICaseAdditionalRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CasePartiesLegalInfoDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseStageEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.mapper.util.StringUtil;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 描述: 案件补录表 case_additional_record 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年12月08日
 */
@Service
@Slf4j
@Transactional(rollbackFor = {Error.class, Exception.class})
public class CaseAdditionalRecordServiceImpl extends MyBatisServiceSupport implements ICaseAdditionalRecordService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseAdditionalRecordServiceImpl.class);

    @Resource
    private CaseAdditionalRecordMapper caseAdditionalRecordMapper;
    @Resource
    private CasePartiesRecordMapper casePartiesRecordMapper;
    @Resource
    private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
    @Resource
    private CaseAppendixRecordMapper caseAppendixRecordMapper;
    @Resource
    private CasePartiesPersonInfoMapper casePartiesPersonInfoMapper;
    @Resource
    private CasePartiesLegalInfoMapper casePartiesLegalInfoMapper;
    @Resource
    private ICaseAdditionalDataReportService caseAdditionalDataReportService;
    @Resource
    private CaseDataReportDecisionServiceImpl decisionService;



    /**
     * 描述：查询补录信息
     *
     * @param id
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public CaseAdditionalRecord getCaseAdditionalRecordById(String id) {
        CaseAdditionalRecord record = new CaseAdditionalRecord();
        record.setId(id);
        return caseAdditionalRecordMapper.selectOne(record);
    }

    /**
     * 描述：保存或更新补录
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveLa(CaseAdditionalRecordDto recordDto) {
        int res = 0;
        List<CaseReasonMainRecord> mainRecordList = recordDto.getMainRecordList();
        List<CasePartiesLegalInfoDto> partiesLegalInfoList = recordDto.getPartiesRecordList();
        List<CasePartiesPersonInfoAddDto> partiesPersonInfoList = recordDto.getPartiesPersonInfoList();
        CaseAdditionalRecord record = new CaseAdditionalRecord();
        BeanUtils.copyProperties(recordDto, record);
        try {
            //解决获取的执法主体统一社会信用码出现空格，导致数据上报失败的问题
            String unicode = recordDto.getUnicode();
            if(StrUtil.isNotEmpty(unicode) && unicode.contains(" ")){
                unicode = unicode.trim();
                record.setUnicode(unicode);
            }
            String caseId = BaseUtil.createUid();
            String caseAuditStatus = "0";
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    caseId = caseAdditionalRecord.getId();
                    caseAuditStatus = caseAdditionalRecord.getCaseAuditStatus();
                }
            }
            record.setId(caseId);
            record.setCaseAuditStatus(caseAuditStatus);
            record.setCaseCreateTime(DateUtil.stringToLocalDateTime(recordDto.getCaseCreateTimeStr(), "yyyy-MM-dd HH:mm"));
            record.setCaseHappenTime(DateUtil.stringToLocalDateTime(recordDto.getCaseHappenTimeStr(), "yyyy-MM-dd HH:mm"));
            record.setCaseRegistTime(DateUtil.stringToLocalDateTime(recordDto.getCaseRegistTimeStr(), "yyyy-MM-dd HH:mm:ss"));
            record.setCaseFileName(recordDto.getAppendixName());
            record.setCaseType(recordDto.getCaseType());
            record.setNameList(recordDto.getNameList());
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                if(!Constant.STRING_0.equals(record.getCaseAuditStatus())){
                    record.setCaseStageStatus(Constant.STRING_5);
                }
                res = caseAdditionalRecordMapper.updateByPrimaryKeySelective(record);
            } else {
                record.setCreateTime(DateUtil.getCurrLocalDateTime());
                res = caseAdditionalRecordMapper.insert(record);
            }

            Map map = new HashMap(16);
            map.put("caseId", caseId);
            casePartiesRecordMapper.deleteAllByCaseId(map);
            casePartiesPersonInfoMapper.deleteAllByCaseId(map);
            casePartiesLegalInfoMapper.deleteAllByCaseId(map);
            if(!ObjectUtils.isEmpty(partiesPersonInfoList)){
                for (CasePartiesPersonInfoAddDto partiesPersonInfo : partiesPersonInfoList) {
                    String partyId = BaseUtil.createUid();
                    partiesPersonInfo.setId(partyId);
                    partiesPersonInfo.setCaseId(caseId);
                    res += casePartiesPersonInfoMapper.insert(partiesPersonInfo);
                    //当事人
                    CasePartiesRecord partiesRecord = new CasePartiesRecord();
                    partiesRecord.setId(BaseUtil.createUid());
                    partiesRecord.setCaseId(caseId);
                    partiesRecord.setCreateTime(DateUtil.getCurrLocalDateTime());
                    partiesRecord.setUpdateTime(DateUtil.getCurrLocalDateTime());
                    partiesRecord.setStatus("1");
                    partiesRecord.setPartyId(partyId);
                    partiesRecord.setPartyType("1");
                    partiesRecord.setPartyName(partiesPersonInfo.getName());
                    partiesRecord.setPartyIdentityCode(partiesPersonInfo.getCertNo());
                    partiesRecord.setPartyIdentityType(partiesPersonInfo.getCertType());
                    partiesRecord.setPartyTel(partiesPersonInfo.getMobile());
                    partiesRecord.setAddressAreas(partiesPersonInfo.getAddressAreas());
                    partiesRecord.setAddressDetail(partiesPersonInfo.getAddress());
                    res += casePartiesRecordMapper.insert(partiesRecord);
                }
            }
            if (!ObjectUtils.isEmpty(partiesLegalInfoList)) {
                for (CasePartiesLegalInfoDto partiesLegalInfoDto: partiesLegalInfoList) {
                    //当事人
                    String partyId = BaseUtil.createUid();
                    CasePartiesRecord partiesRecord = new CasePartiesRecord();
                    partiesRecord.setId(BaseUtil.createUid());
                    partiesRecord.setCaseId(caseId);
                    partiesRecord.setCreateTime(DateUtil.getCurrLocalDateTime());
                    partiesRecord.setUpdateTime(DateUtil.getCurrLocalDateTime());
                    partiesRecord.setStatus("1");
                    partiesRecord.setPartyId(partyId);
                    partiesRecord.setPartyType(partiesLegalInfoDto.getPartyType());
                    partiesRecord.setPartyName(partiesLegalInfoDto.getPartyName());
                    partiesRecord.setPartyIdentityCode(partiesLegalInfoDto.getUniscid());
                    //partiesRecord.setPartyIdentityType(partiesLegalInfoDto.getPartyIdentityType());
                    partiesRecord.setPartyTel(partiesLegalInfoDto.getPartyTel());
                    //partiesRecord.setAddressAreas(partiesLegalInfoDto.getAddress()+","+partiesLegalInfoDto.getAddressAreas());
                    partiesRecord.setAddressDetail(partiesLegalInfoDto.getAddressDetail());
                    res += casePartiesRecordMapper.insert(partiesRecord);
                    //法人
                    CasePartiesLegalInfo partiesLegalInfo = new CasePartiesLegalInfo();
                    BeanUtils.copyProperties(partiesLegalInfoDto, partiesLegalInfo);
                    partiesLegalInfo.setEntName(partiesLegalInfoDto.getPartyName());
                    partiesLegalInfo.setId(partyId);
                    partiesLegalInfo.setLegalName(partiesLegalInfoDto.getLegal());
                    partiesLegalInfo.setAddress(partiesLegalInfoDto.getUnitAddress());
                    partiesLegalInfo.setBusinessAddress(partiesLegalInfoDto.getAddressDetail());
                    partiesLegalInfo.setCaseId(caseId);
                    casePartiesLegalInfoMapper.insert(partiesLegalInfo);
                }
            }
            if (!ObjectUtils.isEmpty(mainRecordList)) {
                caseReasonMainRecordMapper.deleteAllByCaseId(map);
                for (CaseReasonMainRecord mainRecord : mainRecordList) {
                    mainRecord.setId(BaseUtil.createUid());
                    mainRecord.setCaseId(caseId);
                    mainRecord.setStatus("1");
                    res += caseReasonMainRecordMapper.insert(mainRecord);
                }
            }
            recordDto.setId(caseId);
            uploadFile(recordDto);
            if (res > 0) {
                return Result.success(Constant.STRING_SAVE_SUCCESS, caseId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录保存失败" + e.getMessage());
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }


    /**
     * 描述：查询补录列表
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public List<CaseAdditionalRecordDto> getCaseAdditionalRecordList(CaseAdditionalRecordDto recordDto) {
        PageHelper.startPage(recordDto.getPageNum(), recordDto.getLength());
        return caseAdditionalRecordMapper.selectCaseReasonRecordList(recordDto);
    }

    /**
     * 描述：保存或更新补录-告知
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveGz(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    caseAdditionalRecord.setCaseKnowTime(DateUtil.stringToLocalDateTime(recordDto.getCaseKnowTimeStr(), "yyyy-MM-dd"));
                    caseAdditionalRecord.setCaseKnowWay(recordDto.getCaseKnowWay());
                    caseAdditionalRecord.setSendWay(recordDto.getSendWay());
                    caseAdditionalRecord.setSentTime(DateUtil.stringToLocalDateTime(recordDto.getSentTimeStr(), "yyyy-MM-dd"));
                    caseAdditionalRecord.setCaseKnowInform(recordDto.getCaseKnowInform());
                    caseAdditionalRecord.setIsHearing(recordDto.getIsHearing());
                    caseAdditionalRecord.setCasePunishKinds(recordDto.getCasePunishKinds());
                    caseAdditionalRecord.setCaseFileName(recordDto.getAppendixName());
                    if(!Constant.STRING_0.equals(caseAdditionalRecord.getCaseAuditStatus())){
                        caseAdditionalRecord.setCaseStageStatus(Constant.STRING_5);
                    }else {
                        caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
                    }
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
                }
            }
            uploadFile(recordDto);
            return Result.success(Constant.STRING_SAVE_SUCCESS, recordDto.getId());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("保存或更新补录-告知失败");
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 描述：补录 决定保存
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveJd(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    caseAdditionalRecord.setDocumentCreateTime(DateUtil.stringToLocalDateTime(recordDto.getDocumentCreateTimeStr(), "yyyy-MM-dd"));
                    caseAdditionalRecord.setDocumentNumber(recordDto.getDocumentNumber());
                    caseAdditionalRecord.setDecisionSentTime(DateUtil.stringToLocalDateTime(recordDto.getDecisionSentTimeStr(), "yyyy-MM-dd"));
                    caseAdditionalRecord.setDecisionSentWay(recordDto.getDecisionSentWay());
                    caseAdditionalRecord.setCaseDocumentCategory(recordDto.getCaseDocumentCategory());
                    caseAdditionalRecord.setIsImportantCase(recordDto.getIsImportantCase());
                    caseAdditionalRecord.setIsDocumentAudit(recordDto.getIsDocumentAudit());
                    if(YesOrNoEnum.YES.getCode().equals(recordDto.getIsDocumentAudit())){
                        caseAdditionalRecord.setDocumentAuditDate(recordDto.getDocumentAuditDate());
                    }
                    caseAdditionalRecord.setIsNeedCollectiveDiscuss(recordDto.getIsNeedCollectiveDiscuss());
                    if(IsConfirmEnum.IsConfirmXY.getCode().equals(recordDto.getIsNeedCollectiveDiscuss())){
                        caseAdditionalRecord.setNeedCollectiveDiscussTime(DateUtil.stringToDate(recordDto.getNeedCollectiveDiscussTimeStr(), "yyyy-MM-dd"));
                        caseAdditionalRecord.setNeedCollectiveDiscussReason(StringEscapeUtils.unescapeHtml4(recordDto.getNeedCollectiveDiscussReason()));
                    }
                    caseAdditionalRecord.setIllegalFact(recordDto.getIllegalFact());
                    caseAdditionalRecord.setRelateEvidence(recordDto.getRelateEvidence());
                    caseAdditionalRecord.setPunishBasis(recordDto.getPunishBasis());
                    caseAdditionalRecord.setPunishKinds(recordDto.getPunishKinds());
                    caseAdditionalRecord.setDraftPunishMoney(recordDto.getDraftPunishMoney());
                    caseAdditionalRecord.setConfiscatePunishMoney(recordDto.getConfiscatePunishMoney());
                    caseAdditionalRecord.setConfiscateIllegalPunishMoney(recordDto.getConfiscateIllegalPunishMoney());
                    caseAdditionalRecord.setCaseWithholdLicenseName(recordDto.getCaseWithholdLicenseName());
                    caseAdditionalRecord.setCaseWithholdLicenseCode(recordDto.getCaseWithholdLicenseCode());
                    if (StringUtil.isNotEmpty(recordDto.getCaseWithholdLicenseEndTimeStr())){
                        String caseWithholdLicenseEndTimeStr = recordDto.getCaseWithholdLicenseEndTimeStr();
                        caseAdditionalRecord.setCaseWithholdLicenseEndTime(DateUtil.stringToLocalDateTime(caseWithholdLicenseEndTimeStr, "yyyy-MM-dd"));
                    }
                    caseAdditionalRecord.setCaseRevocationLicenseCode(recordDto.getCaseRevocationLicenseCode());
                    caseAdditionalRecord.setCaseRevocationLicenseName(recordDto.getCaseRevocationLicenseName());
                    String caseRevocationLicenseEndTimeStr = recordDto.getCaseRevocationLicenseEndTimeStr();
                    if (StringUtil.isNotEmpty(caseRevocationLicenseEndTimeStr)){
                        caseAdditionalRecord.setCaseRevocationLicenseEndTime(DateUtil.stringToLocalDateTime(caseRevocationLicenseEndTimeStr, "yyyy-MM-dd"));
                    }
                    caseAdditionalRecord.setCaseDetentionDay(recordDto.getCaseDetentionDay());
                    if (StringUtil.isNotEmpty(recordDto.getCaseDetentionStartTimeStr())) {
                        caseAdditionalRecord.setCaseDetentionStartTime(DateUtil.stringToLocalDateTime(recordDto.getCaseDetentionStartTimeStr(), "yyyy-MM-dd"));
                    }
                    if (StringUtil.isNotEmpty(recordDto.getCaseDetentionEndTimeStr())) {
                        caseAdditionalRecord.setCaseDetentionEndTime(DateUtil.stringToLocalDateTime(recordDto.getCaseDetentionEndTimeStr(), "yyyy-MM-dd"));
                    }
                    if (StringUtil.isNotEmpty(recordDto.getCaseWithholdLicenseStartTimeStr())){
                        String caseWithholdLicenseStartTimeStr = recordDto.getCaseWithholdLicenseStartTimeStr();
                        caseAdditionalRecord.setCaseWithholdLicenseStartTime(DateUtil.stringToDate(caseWithholdLicenseStartTimeStr, "yyyy-MM-dd"));
                    }
                    if (StringUtil.isNotEmpty(recordDto.getCaseRevocationLicenseStartTimeStr())){
                        String caseRevocationLicenseStartTimeStr = recordDto.getCaseRevocationLicenseStartTimeStr();
                        caseAdditionalRecord.setCaseRevocationLicenseStartTime(DateUtil.stringToDate(caseRevocationLicenseStartTimeStr, "yyyy-MM-dd"));
                    }
                    caseAdditionalRecord.setIsPublicity(recordDto.getIsPublicity());
                    caseAdditionalRecord.setPublicityContent(StringEscapeUtils.escapeHtml4(recordDto.getPublicityContent()));
                    caseAdditionalRecord.setCaseDecisionFileName(recordDto.getAppendixName());
                    if(!Constant.STRING_0.equals(caseAdditionalRecord.getCaseAuditStatus())){
                        caseAdditionalRecord.setCaseStageStatus(Constant.STRING_5);
                    }else {
                        caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
                    }
                    caseAdditionalRecord.setConfiscateIllegalProperty(recordDto.getConfiscateIllegalProperty());
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
                }
            }
            uploadFile(recordDto);
            return Result.success(Constant.STRING_SAVE_SUCCESS, recordDto.getId());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录 决定保存失败");
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 描述：补录 执行保存
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveZx(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    caseAdditionalRecord.setIsExecutePunish(recordDto.getIsExecutePunish());
                    caseAdditionalRecord.setCaseCloseStatus(recordDto.getCaseCloseStatus());
                    if(CaseAdditionalRecordCaseTypeEnums.A_1.getCode().equals(recordDto.getIsExecutePunish())){
                        caseAdditionalRecord.setExecuteFinishDate(DateUtil.stringToLocalDateTime(recordDto.getExecuteFinishDateStr(), "yyyy-MM-dd"));
                        caseAdditionalRecord.setExecuteWay(recordDto.getExecuteWay());
                        caseAdditionalRecord.setIsStages(recordDto.getIsStages());
                        caseAdditionalRecord.setIsDelay(recordDto.getIsDelay());
                    }else{
                        caseAdditionalRecord.setExecutePunishCause(StringEscapeUtils.unescapeHtml4(recordDto.getExecutePunishCause()));
                    }
                    caseAdditionalRecord.setCasePunishResult(StringEscapeUtils.unescapeHtml4(recordDto.getCasePunishResult()));
                    caseAdditionalRecord.setCaseExecuteFileName(recordDto.getAppendixName());
                    if(!Constant.STRING_0.equals(caseAdditionalRecord.getCaseAuditStatus())){
                        caseAdditionalRecord.setCaseStageStatus(Constant.STRING_5);
                    }else {
                        caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
                    }
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
                }
            }
            uploadFile(recordDto);
            return Result.success(Constant.STRING_SAVE_SUCCESS, recordDto.getId());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录 执行保存失败");
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 补录 执行保存（未结案）
     * @param recordDto
     * @return
     */
    @Override
    public Result<String> saveZxCaseNotClose(CaseAdditionalRecordDto recordDto){
        CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
        caseAdditionalRecord.setCaseCloseStatus(recordDto.getCaseCloseStatus());
        caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
        caseAdditionalRecord.setOrgCode(recordDto.getOrgCode());
        int re = caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
        int flag = this.reportData(re, recordDto);
        if(flag == 1) {
            return Result.success("补录成功", recordDto.getId());
        }else{
            return Result.success("补录失败", recordDto.getId());
        }
    }

    /**
     * 描述：补录 结案保存
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveJa(CaseAdditionalRecordDto recordDto) {
        try {
            int re = 0;
            String caseAuditStatus = "";
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    caseAdditionalRecord.setIsCaseCondition(recordDto.getIsCaseCondition());
                    caseAdditionalRecord.setCaseFinishDate(DateUtil.stringToLocalDateTime(recordDto.getCaseFinishDateStr(), "yyyy-MM-dd"));
                    caseAdditionalRecord.setIsCasePunish(recordDto.getIsCasePunish());
                    caseAdditionalRecord.setCaseFinishFileName(recordDto.getAppendixName());
                    caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
                    re = caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
                    caseAuditStatus=caseAdditionalRecord.getCaseAuditStatus();
                }
            }
            uploadFile(recordDto);
            int flag = this.reportData(re, recordDto);
            if(StringUtil.isNotEmpty(caseAuditStatus)&&(!"5".equals(caseAuditStatus) && !"4".equals(caseAuditStatus))){
                if(flag == 1) {
                    return Result.success("补录成功", recordDto.getId());
                }else{
                    return Result.error(500, "补录失败", recordDto.getId());
                }
            }else{
                if(flag == 1) {
                    return Result.success("修改成功", recordDto.getId());
                }else{
                    return Result.success(500, "修改失败", recordDto.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录 结案保存失败");
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 补录提交时，上报数据
     * @param re
     * @param recordDto
     */
    private int reportData(int re, CaseAdditionalRecordDto recordDto){
        int flag = 0;
        CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
        CaseAdditionalRecord updateCaseAdditionalRecord=new CaseAdditionalRecord();
        updateCaseAdditionalRecord.setId(recordDto.getId());

        try {
            //上报数据
            if(re > 0){
                boolean reportRe = false;
                //简易程序暂时不上报
                if (Constant.STRING_2.equals(caseAdditionalRecord.getCaseType())) {
                    reportRe = true;
                } else {
                    reportRe = caseAdditionalDataReportService.caseAdditionalDataReport(recordDto.getId());
                }
                //CaseAdditionalRecord caseAdditionalRecord = caseAdditionalRecordMapper.selectByPrimaryKey(recordDto.getId());
                if(reportRe){
                    updateCaseAdditionalRecord.setCaseAuditStatus("4");
                    updateCaseAdditionalRecord.setCaseSuccessTime(DateUtil.getCurrLocalDateTime());
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(updateCaseAdditionalRecord);
                    flag = 1;
                }else {
                    updateCaseAdditionalRecord.setCaseAuditStatus("5");
//                    caseAdditionalRecord.setCaseSuccessTime(DateUtil.getCurrLocalDateTime());
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(updateCaseAdditionalRecord);
                    flag = 2;
                }
            }
        }catch (Exception e){
            log.info("------------上报数据失败，补录ID：{}--------------", recordDto.getId());
            updateCaseAdditionalRecord.setCaseAuditStatus("5");
//                    caseAdditionalRecord.setCaseSuccessTime(DateUtil.getCurrLocalDateTime());
            caseAdditionalRecordMapper.updateByPrimaryKeySelective(updateCaseAdditionalRecord);
            flag = 2;
        }
        return flag;
    }

    /**
     * 描述：补录 审批表信息保存
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> saveSp(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    if(StringUtil.isNotEmpty(recordDto.getCaseRecordReason())) {
                        caseAdditionalRecord.setCaseRecordReason(StringEscapeUtils.unescapeHtml4(recordDto.getCaseRecordReason()));
                    }
                    if(StringUtil.isNotEmpty(recordDto.getCaseRecordContent())) {
                        caseAdditionalRecord.setCaseRecordContent(StringEscapeUtils.unescapeHtml4(recordDto.getCaseRecordContent()));
                    }
                    caseAdditionalRecord.setCaseStageStatus(recordDto.getCaseStageStatus());
                    caseAdditionalRecord.setCaseAuditStatus(recordDto.getCaseAuditStatus());
                    caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
                }
            }
            return Result.success(Constant.STRING_SAVE_SUCCESS, recordDto.getId());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("审批表信息保存失败");
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 描述：补录详情
     *
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<CaseAdditionalRecordDto> getAdditionalRecord(CaseAdditionalRecordDto recordDto) {
        try {
            CaseAdditionalRecordDto caseAdditionalRecordDto = new CaseAdditionalRecordDto();
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                if (!ObjectUtils.isEmpty(caseAdditionalRecord)) {
                    BeanUtils.copyProperties(caseAdditionalRecord, caseAdditionalRecordDto);
                    if (CaseAdditionalRecordFlowEnums.A_1.getCode().equals(recordDto.getCaseStageStatus())) {
                        Example mainExample = new Example(CaseReasonMainRecord.class);
                        Example.Criteria mainCriteria = mainExample.createCriteria();
                        mainCriteria.andEqualTo("caseId", recordDto.getId());
                        List<CaseReasonMainRecord> mainRecordList = caseReasonMainRecordMapper.selectByExample(mainExample);
                        caseAdditionalRecordDto.setPartiesRecordList(getCasePartiesLegalInfoList(recordDto));
                        caseAdditionalRecordDto.setMainRecordList(mainRecordList);
                        caseAdditionalRecordDto.setAppendixRecordList(getCaseAppendixRecordList(recordDto));
                        caseAdditionalRecordDto.setPartiesPersonInfoList(getCasePartiesPersonInfoList(recordDto));
                    } else if (CaseAdditionalRecordFlowEnums.A_2.getCode().equals(recordDto.getCaseStageStatus())) {
                        Example mainExample = new Example(CaseReasonMainRecord.class);
                        Example.Criteria mainCriteria = mainExample.createCriteria();
                        mainCriteria.andEqualTo("caseId", recordDto.getId());
                        List<CaseReasonMainRecord> mainRecordList = caseReasonMainRecordMapper.selectByExample(mainExample);
                        caseAdditionalRecordDto.setMainRecordList(mainRecordList);
                        caseAdditionalRecordDto.setAppendixRecordList(getCaseAppendixRecordList(recordDto));
                    } else if (CaseAdditionalRecordFlowEnums.A_3.getCode().equals(recordDto.getCaseStageStatus())) {
                        caseAdditionalRecordDto.setAppendixRecordList(getCaseAppendixRecordList(recordDto));
                    } else if (CaseAdditionalRecordFlowEnums.A_4.getCode().equals(recordDto.getCaseStageStatus())) {
                        caseAdditionalRecordDto.setAppendixRecordList(getCaseAppendixRecordList(recordDto));
                    } else if (CaseAdditionalRecordFlowEnums.A_5.getCode().equals(recordDto.getCaseStageStatus())) {
                        caseAdditionalRecordDto.setAppendixRecordList(getCaseAppendixRecordList(recordDto));
                    }
                    if(ObjectUtil.isNotEmpty(caseAdditionalRecord.getNeedCollectiveDiscussTime())){
                        caseAdditionalRecordDto.setNeedCollectiveDiscussTimeStr(cn.hutool.core.date.DateUtil.format(caseAdditionalRecord.getNeedCollectiveDiscussTime(), DatePattern.NORM_DATE_PATTERN));
                    }
                }
            }
            return Result.success(Constant.STRING_GET_SUCCESS, caseAdditionalRecordDto);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("审批表信息保存失败");
        }
        return Result.error(Constant.STRING_GET_FAIL);
    }
    /**
     * 描述：补录-删除
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> deleteRecord(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                //如果是已上报成功，则需要上报删除案件，暂不支持删除
                if( Constant.STRING_4.equals(caseAdditionalRecord.getCaseAuditStatus())){
                    return Result.error("已成功上报数据，暂不支持删除！");
                }
                caseAdditionalRecordMapper.deleteByPrimaryKey(caseAdditionalRecord);
                Map map = new HashMap(16);
                map.put("caseId", recordDto.getId());
                caseReasonMainRecordMapper.deleteAllByCaseId(map);
                casePartiesRecordMapper.deleteAllByCaseId(map);
                caseAppendixRecordMapper.deleteAllByCaseId(map);
                casePartiesPersonInfoMapper.deleteAllByCaseId(map);
                casePartiesLegalInfoMapper.deleteAllByCaseId(map);
            }
            return Result.success(Constant.STRING_GET_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录删除失败");
        }
        return Result.error(Constant.STRING_GET_FAIL);
    }
    /**
     * 描述：补录-详情
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<CaseAdditionalRecordDto> detail(CaseAdditionalRecordDto recordDto) {
        try {
            CaseAdditionalRecordDto caseAdditionalRecordDto = new CaseAdditionalRecordDto();
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                BeanUtils.copyProperties(caseAdditionalRecord, caseAdditionalRecordDto);
                Example mainExample = new Example(CaseReasonMainRecord.class);
                Example.Criteria mainCriteria = mainExample.createCriteria();
                mainCriteria.andEqualTo("caseId", recordDto.getId());
                List<CaseReasonMainRecord> mainRecordList = caseReasonMainRecordMapper.selectByExample(mainExample);
                caseAdditionalRecordDto.setPartiesRecordList(getCasePartiesLegalInfoList(recordDto));
                caseAdditionalRecordDto.setMainRecordList(mainRecordList);
                caseAdditionalRecordDto.setAppendixRecordList(getAllCaseAppendixRecordList(recordDto));
                caseAdditionalRecordDto.setPartiesPersonInfoList(getCasePartiesPersonInfoList(recordDto));
                caseAdditionalRecordDto.setCaseSource(getCaseSourceName(caseAdditionalRecordDto));
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getCaseIsEntrust())){
                    caseAdditionalRecordDto.setCaseIsEntrust(Constant.STRING_1.equals(caseAdditionalRecordDto.getCaseIsEntrust())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setCaseIsEntrust("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getCaseKnowWay())){
                    caseAdditionalRecordDto.setCaseKnowWay(Constant.STRING_0.equals(caseAdditionalRecordDto.getCaseKnowWay())?"口头":"书面");
                }else{
                    caseAdditionalRecordDto.setCaseKnowWay("--");
                }
                caseAdditionalRecordDto.setCaseKnowInform(getInformName(caseAdditionalRecordDto));
                caseAdditionalRecordDto.setSendWay(getSendWayName(caseAdditionalRecordDto));
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getCaseDocumentCategory())){
                    caseAdditionalRecordDto.setCaseDocumentCategory(Constant.STRING_1.equals(caseAdditionalRecordDto.getCaseDocumentCategory())?"予以处罚":"不予处罚");
                }else{
                    caseAdditionalRecordDto.setCaseDocumentCategory("--");
                }

                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsImportantCase())){
                    caseAdditionalRecordDto.setIsImportantCase(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsImportantCase())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsImportantCase("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsDocumentAudit())){
                    caseAdditionalRecordDto.setIsDocumentAudit(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsDocumentAudit())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsDocumentAudit("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsNeedCollectiveDiscuss())){
                    caseAdditionalRecordDto.setIsNeedCollectiveDiscuss(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsNeedCollectiveDiscuss())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsNeedCollectiveDiscuss("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsStages())){
                    caseAdditionalRecordDto.setIsStages(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsStages())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsStages("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsDelay())){
                    caseAdditionalRecordDto.setIsDelay("1".equals(caseAdditionalRecordDto.getIsDelay())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsDelay("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getExecuteWay())){
                    caseAdditionalRecordDto.setExecuteWay(Constant.STRING_1.equals(caseAdditionalRecordDto.getExecuteWay())?"强制执行":"自觉履行");
                }else{
                    caseAdditionalRecordDto.setExecuteWay("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsPublicity())){
                    caseAdditionalRecordDto.setIsPublicity(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsPublicity())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsPublicity("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsExecutePunish())){
                    caseAdditionalRecordDto.setIsExecutePunish(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsExecutePunish())?"执行处罚决定":"未执行处罚决定");
                }else{
                    caseAdditionalRecordDto.setIsExecutePunish("--");
                }
                caseAdditionalRecordDto.setCaseType(getCaseTypeName(caseAdditionalRecordDto));
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsCasePunish())){
                    caseAdditionalRecordDto.setIsCasePunish(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsCasePunish())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsCasePunish("--");
                }
                if(StringUtil.isNotEmpty(caseAdditionalRecordDto.getIsCaseCondition())){
                    caseAdditionalRecordDto.setIsCaseCondition(Constant.STRING_1.equals(caseAdditionalRecordDto.getIsCaseCondition())?"是":"否");
                }else{
                    caseAdditionalRecordDto.setIsCaseCondition("--");
                }
                caseAdditionalRecordDto.setPunishKindsContent(getPunishKindsContent(caseAdditionalRecordDto));
                caseAdditionalRecordDto.setDecisionSentWay(getDecisionSentWayName(caseAdditionalRecordDto));
            }
            return Result.success(Constant.STRING_SAVE_SUCCESS,caseAdditionalRecordDto);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录详情失败");
        }
        return Result.error(Constant.STRING_GET_FAIL);
    }
    /**
     * 描述：补录-提交
     * @param recordDto
     * @return
     * @author wangfawei
     * @date 2022-12-8
     */
    @Override
    public Result<String> submit(CaseAdditionalRecordDto recordDto) {
        try {
            if (StringUtil.isNotEmpty(recordDto.getId())) {
                CaseAdditionalRecord caseAdditionalRecord = getCaseAdditionalRecordById(recordDto.getId());
                caseAdditionalRecord.setCaseAuditStatus("1");
                caseAdditionalRecordMapper.updateByPrimaryKeySelective(caseAdditionalRecord);
            }
            return Result.success(Constant.STRING_GET_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录提交失败");
        }
        return Result.error(Constant.STRING_GET_FAIL);
    }

    /**
     * 补录附件保存
     *
     * @param recordDto
     */
    private void uploadFile(CaseAdditionalRecordDto recordDto) {
        try {
            CaseAppendixRecord caseAppendixRecord = getCaseAppendixRecord(recordDto);
            List<CaseAppendixRecord> appendixRecordList = recordDto.getAppendixRecordList();
            if (!ObjectUtils.isEmpty(appendixRecordList)) {
                Map<String, Object> map = new HashMap<>(16);
                map.put("caseStageCode", caseAppendixRecord.getCaseStageCode());
                map.put("caseId", recordDto.getId());
                caseAppendixRecordMapper.deleteAllByCaseId(map);
                for (CaseAppendixRecord appendixRecord: appendixRecordList) {
                    appendixRecord.setId(BaseUtil.createUid());
                    appendixRecord.setCaseId(recordDto.getId());
                    appendixRecord.setCaseStageCode(caseAppendixRecord.getCaseStageCode());
                    appendixRecord.setCaseStageName(caseAppendixRecord.getCaseStageName());
                    String appendixNameVal = appendixRecord.getAppendixName();
                    String[] appendixNameBef = appendixNameVal.split("\\.");
                    appendixRecord.setAppendixName(appendixNameVal);
                    appendixRecord.setIsDelete("0");
                    appendixRecord.setUploadTime(DateUtil.getCurrLocalDateTime());
                    appendixRecord.setAppendixNamePrefix(appendixNameBef[0]);
                    appendixRecord.setAppendixNameSuffix(appendixNameBef[1]);
                    appendixRecord.setAppendixStatus("1");
                    caseAppendixRecordMapper.insert(appendixRecord);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("补录附件保存失败");
        }

    }

    private CaseAppendixRecord getCaseAppendixRecord(CaseAdditionalRecordDto recordDto){
        CaseAppendixRecord appendixRecord = new CaseAppendixRecord();
        String caseStageCode = CaseStageEnum.CASE_REGISTER.getCode();
        String caseStageName = CaseStageEnum.CASE_REGISTER.getDes();
        if (CaseAdditionalRecordFlowEnums.A_2.getCode().equals(recordDto.getCaseStageStatus())) {
            caseStageCode = CaseStageEnum.PUNISH_INFORM.getCode();
            caseStageName = CaseStageEnum.PUNISH_INFORM.getDes();
        } else if (CaseAdditionalRecordFlowEnums.A_3.getCode().equals(recordDto.getCaseStageStatus())) {
            caseStageCode = CaseStageEnum.PUNISH_DECIDE.getCode();
            caseStageName = CaseStageEnum.PUNISH_DECIDE.getDes();
        } else if (CaseAdditionalRecordFlowEnums.A_4.getCode().equals(recordDto.getCaseStageStatus())) {
            caseStageCode = CaseStageEnum.PUNISH_EXECUTION.getCode();
            caseStageName = CaseStageEnum.PUNISH_EXECUTION.getDes();
        } else if (CaseAdditionalRecordFlowEnums.A_5.getCode().equals(recordDto.getCaseStageStatus())) {
            caseStageCode = CaseStageEnum.CLOSE_ARCHIVING.getCode();
            caseStageName = CaseStageEnum.CLOSE_ARCHIVING.getDes();
        }
        appendixRecord.setCaseStageCode(caseStageCode);
        appendixRecord.setCaseStageName(caseStageName);
        return appendixRecord;
    }

    /**
     * 描述：查询附件
     * @param recordDto
     * @return
     */
  private List<CaseAppendixRecord> getCaseAppendixRecordList(CaseAdditionalRecordDto recordDto){
      CaseAppendixRecord appendixRecord = getCaseAppendixRecord(recordDto);
      Example example = new Example(CaseAppendixRecord.class);
      Example.Criteria criteria = example.createCriteria();
      if(StringUtil.isNotEmpty(appendixRecord.getCaseStageCode())) {
          criteria.andEqualTo("caseStageCode", appendixRecord.getCaseStageCode());
      }
      criteria.andEqualTo("caseId", recordDto.getId());
      return caseAppendixRecordMapper.selectByExample(example);
  }
    /**
     * 描述：查询所有附件
     * @param recordDto
     * @return
     */
    private List<CaseAppendixRecord> getAllCaseAppendixRecordList(CaseAdditionalRecordDto recordDto){
        Example example = new Example(CaseAppendixRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("caseId", recordDto.getId());
        return caseAppendixRecordMapper.selectByExample(example);
    }
    /**
     * 描述：查询个人
     * @param recordDto
     * @return
     */
    private List<CasePartiesPersonInfoAddDto> getCasePartiesPersonInfoList(CaseAdditionalRecordDto recordDto){
        List<CasePartiesPersonInfoAddDto> casePartiesPersonInfoDtoList = new ArrayList<>();
        Example example = new Example(CasePartiesRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("caseId",recordDto.getId())
                .andEqualTo("status",Constant.STRING_1).andEqualTo("partyType", PartyTypeEnum.PERSON.getCode());
        List<CasePartiesRecord> casePartiesRecords = casePartiesRecordMapper.selectByExample(example);
        casePartiesRecords.forEach(e -> {
            CasePartiesPersonInfoAddDto dto = new CasePartiesPersonInfoAddDto();
            CasePartiesPersonInfo casePartiesPersonInfo = casePartiesPersonInfoMapper.selectByPrimaryKey(e.getPartyId());
            BeanUtils.copyProperties(casePartiesPersonInfo, dto);
            dto.setAddressDetail(e.getAddressDetail());
            casePartiesPersonInfoDtoList.add(dto);

        });
        return casePartiesPersonInfoDtoList;
    }

    private String getCaseSourceName(CaseAdditionalRecordDto caseAdditionalRecordDto){
        if(CaseSourceEnum.CASE_SOURCE_XCZFX.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_XCZFX.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_SHJB.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_SHJB.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_YGBMYS.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_YGBMYS.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_SJXZJGJB.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_SJXZJGJB.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_XJXZJGBQ.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_XJXZJGBQ.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_FXCZF.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_FXCZF.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_JGJCBG.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_JGJCBG.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_ZXZJCZFX.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_ZXZJCZFX.getDes();
        }else if(CaseSourceEnum.CASE_SOURCE_QT.getCode().equals(caseAdditionalRecordDto.getCaseSource())){
            return CaseSourceEnum.CASE_SOURCE_QT.getDes();
        }else{
            return CaseSourceEnum.CASE_SOURCE_QT_TXDC.getDes();
        }
    }

    private String getInformName(CaseAdditionalRecordDto caseAdditionalRecordDto){
        String informName = "";
        String caseKnowInform = caseAdditionalRecordDto.getCaseKnowInform();
        if(caseKnowInform.length()>0) {
            String[] caseKnowInformArr = caseKnowInform.split(",");
            for(int i =0;i<caseKnowInformArr.length;i++) {
                if (CaseAdditionalRecordInformEnums.A_1.getCode().equals(caseKnowInformArr[i])) {
                    informName += CaseAdditionalRecordInformEnums.A_1.getDes() + ",";
                } else  if (CaseAdditionalRecordInformEnums.A_2.getCode().equals(caseKnowInformArr[i])){
                    informName += CaseAdditionalRecordInformEnums.A_2.getDes() + ",";
                }else{
                    informName = "";
                }
            }
        }
        if(informName.length()>0){
            informName = informName.substring(0,informName.length()-1);
        }
        return informName;
    }

    /**
     * 描述：获取发送方式名称
     * @param caseAdditionalRecordDto
     * @return
     */
    private String getSendWayName(CaseAdditionalRecordDto caseAdditionalRecordDto) {
        if (SendWayEnums.DIRECT.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.DIRECT.getDes();
        } else if (SendWayEnums.INDWELLING.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.INDWELLING.getDes();
        } else if (SendWayEnums.ENTRUST.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.ENTRUST.getDes();
        } else if (SendWayEnums.EMAIL.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.EMAIL.getDes();
        } else if (SendWayEnums.NOTICE.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.NOTICE.getDes();
        } else if (SendWayEnums.TEXT_MSG.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.TEXT_MSG.getDes();
        } else if (SendWayEnums.LOCAL_MSG.getCode().equals(caseAdditionalRecordDto.getSendWay())) {
            return SendWayEnums.LOCAL_MSG.getDes();
        } else {
            return SendWayEnums.SENT_REGISTER.getDes();
        }
    }
        /**
         * 描述：获取案件类型名称
         * @param caseAdditionalRecordDto
         * @return
         */
        private String getCaseTypeName(CaseAdditionalRecordDto caseAdditionalRecordDto){
            if(CaseAdditionalRecordCaseTypeEnums.A_1.getCode().equals(caseAdditionalRecordDto.getCaseType())){
                return CaseAdditionalRecordCaseTypeEnums.A_1.getDes();
            }else if(CaseAdditionalRecordCaseTypeEnums.A_2.getCode().equals(caseAdditionalRecordDto.getCaseType())){
                return CaseAdditionalRecordCaseTypeEnums.A_2.getDes();
            }else{
                return CaseAdditionalRecordCaseTypeEnums.A_3.getDes();
            }
        }

        private List<CasePartiesLegalInfoDto> getCasePartiesLegalInfoList(CaseAdditionalRecordDto recordDto){
            List<CasePartiesLegalInfoDto> legalInfoDtoList = new ArrayList<>(50);
            Example example = new Example(CasePartiesLegalInfo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("caseId", recordDto.getId());
            List<CasePartiesLegalInfo> recordList = casePartiesLegalInfoMapper.selectByExample(example);
            if(recordList.size()>0) {

                for (CasePartiesLegalInfo partiesLegalInfo: recordList) {
                    CasePartiesLegalInfoDto legalInfoDto = new CasePartiesLegalInfoDto();
                    BeanUtil.copyProperties(partiesLegalInfo,legalInfoDto);
                    Example exampleRecord = new Example(CasePartiesRecord.class);
                    Example.Criteria criteriaRecord = exampleRecord.createCriteria();
                    criteriaRecord.andEqualTo("caseId", recordDto.getId()).andEqualTo("partyId", partiesLegalInfo.getId());
                    List<CasePartiesRecord> partiesRecordList = casePartiesRecordMapper.selectByExample(exampleRecord);
                    if(partiesRecordList.size()>0){
                        CasePartiesRecord partiesRecord = partiesRecordList.get(0);
                        legalInfoDto.setPhone(partiesRecord.getPartyTel());
                        legalInfoDto.setAddressAreas(partiesRecord.getAddressAreas());
                        legalInfoDto.setAddressDetail(partiesRecord.getAddressDetail());
                        legalInfoDto.setAddress(partiesRecord.getAddressDetail());
                        legalInfoDto.setPartyType(partiesRecord.getPartyType());
                    }

                    legalInfoDtoList.add(legalInfoDto);
                }
            }
            return legalInfoDtoList;
        }

    /**
     * 处罚内容生成规则-警告,罚款,没收违法所得,没收非法财物,暂扣许可证,通报批评,降低资质等级,吊销许可证,限制生产经营,责令停产停业,责令关闭,限制从业,行政拘留,其他
     1、罚款：处于罚款人民币（金额大写）整（¥+阿拉伯数字，精确到小数点后2位）
     2、没收违法所得：没收违法所得人民币（金额大写）整（¥+阿拉伯数字，精确到小数点后2位）
     3、没收非法财物：没收非法财物包括（财物描述），价值人民币（金额大写）整（¥+阿拉伯数字，精确到小数点后2位）
     4、暂扣许可证：暂扣（许可证名称，许可证编号）自（起始日期）至（截止日期）
     5、吊销许可证：吊销（许可证名称，许可证编号）自（起始日期）至（截止日期）
     6、行政拘留：行政拘留7日，自（起始日期）至（截止日期）
     * @param caseAdditionalRecordDto
     * @return
     */
    private String getPunishKindsContent(CaseAdditionalRecordDto caseAdditionalRecordDto){
            String punishKindsContent = "";
        try {
            String punishKindA = caseAdditionalRecordDto.getPunishKinds();
            String[] punishKindsArr = punishKindA.split(",");
            for(int i=0;i<punishKindsArr.length;i++) {
                String punishKinds = punishKindsArr[i].toString();
                if (punishKinds.contains("警告")) {
                    punishKindsContent += "警告" + ",";
                }else if (punishKinds.contains("罚款")) {
                    String tmpPayTotalMoney = ConvertUpMoneyUtil.toChinese(caseAdditionalRecordDto.getDraftPunishMoney());
                    punishKindsContent += "处于罚款人民币" + tmpPayTotalMoney + "整（¥" + caseAdditionalRecordDto.getDraftPunishMoney() + "）" + ",";
                }else  if(punishKinds.contains("没收违法所得")){
                    String tmpPayTotalMoney = ConvertUpMoneyUtil.toChinese(caseAdditionalRecordDto.getConfiscatePunishMoney());
                    punishKindsContent += "没收违法所得人民币" + tmpPayTotalMoney + "整（¥" + caseAdditionalRecordDto.getConfiscatePunishMoney() + "）" + ",";
                }else  if(punishKinds.contains("没收非法财物")){
                    String tmpPayTotalMoney = ConvertUpMoneyUtil.toChinese(caseAdditionalRecordDto.getConfiscateIllegalPunishMoney());
                    punishKindsContent += "没收非法财物包括财物描述，价值人民币" + tmpPayTotalMoney + "整（¥" + caseAdditionalRecordDto.getConfiscateIllegalPunishMoney() + "）" + ",";
                }else  if(punishKinds.contains("暂扣许可证")){
                    Date caseWithholdLicenseStartTime = caseAdditionalRecordDto.getCaseWithholdLicenseStartTime();
                    String caseWithholdLicenseEndTimeStart = DateUtil.dateToString(caseWithholdLicenseStartTime,"yyyy-MM-dd");
                    LocalDateTime caseWithholdLicenseEndTime = caseAdditionalRecordDto.getCaseWithholdLicenseEndTime();
                    String caseWithholdLicenseEndTimeEnd= DateUtil.getStringAsLocalDateTime(caseWithholdLicenseEndTime,"yyyy-MM-dd");
                    punishKindsContent += "暂扣（"+caseAdditionalRecordDto.getCaseWithholdLicenseName()+"，"+caseAdditionalRecordDto.getCaseWithholdLicenseName()+"）自"+caseWithholdLicenseEndTimeStart+"至"+caseWithholdLicenseEndTimeEnd+"";
                }else  if(punishKinds.contains("吊销许可证")){
                    Date caseRevocationLicenseStartTime = caseAdditionalRecordDto.getCaseRevocationLicenseStartTime();
                    String caseRevocationLicenseEndTimeStart = DateUtil.dateToString(caseRevocationLicenseStartTime,"yyyy-MM-dd");
                    LocalDateTime caseRevocationLicenseEndTime = caseAdditionalRecordDto.getCaseRevocationLicenseEndTime();
                    String caseRevocationLicenseEndTimeEnd = DateUtil.getStringAsLocalDateTime(caseRevocationLicenseEndTime,"yyyy-MM-dd");
                    punishKindsContent += "吊销（"+caseAdditionalRecordDto.getCaseRevocationLicenseName()+"，"+caseAdditionalRecordDto.getCaseRevocationLicenseCode()+"）自"+caseRevocationLicenseEndTimeStart+"至"+caseRevocationLicenseEndTimeEnd+"";
                }else  if(punishKinds.contains("行政拘留")){
                    LocalDateTime caseDetentionStartTime = caseAdditionalRecordDto.getCaseDetentionStartTime();
                    String caseDetentionStartTimeStart = DateUtil.getStringAsLocalDateTime(caseDetentionStartTime,"yyyy-MM-dd");
                    LocalDateTime caseDetentionEndTime = caseAdditionalRecordDto.getCaseDetentionEndTime();
                    String caseDetentionEndTimeEnd= DateUtil.getStringAsLocalDateTime(caseDetentionEndTime,"yyyy-MM-dd");
                    punishKindsContent += "行政拘留"+String.valueOf(caseAdditionalRecordDto.getCaseDetentionDay())+"日，自"+caseDetentionStartTimeStart+"至"+caseDetentionEndTimeEnd+"";
                }else if (punishKinds.contains("通报批评")) {
                    punishKindsContent += "通报批评" + ",";
                }else if (punishKinds.contains("降低资质等级")) {
                    punishKindsContent += "降低资质等级" + ",";
                }else if (punishKinds.contains("限制生产经营")) {
                    punishKindsContent += "限制生产经营" + ",";
                }else if (punishKinds.contains("责令停产停业")) {
                    punishKindsContent += "责令停产停业" + ",";
                }else if (punishKinds.contains("责令关闭")) {
                    punishKindsContent += "责令关闭" + ",";
                }else if (punishKinds.contains("限制从业")) {
                    punishKindsContent += "限制从业" + ",";
                }else{
                    punishKindsContent += "其他" + ",";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("处罚种类异常"+e.getMessage());
        }
        if(punishKindsContent.length()>0){
                punishKindsContent = punishKindsContent.substring(0,punishKindsContent.length()-1);
            }
            return punishKindsContent;
        }
    /**
     * 描述：获取决定发送方式名称
     * @param caseAdditionalRecordDto
     * @return
     */
    private String getDecisionSentWayName(CaseAdditionalRecordDto caseAdditionalRecordDto) {
        if (SendWayEnums.DIRECT.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.DIRECT.getDes();
        } else if (SendWayEnums.INDWELLING.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.INDWELLING.getDes();
        } else if (SendWayEnums.ENTRUST.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.ENTRUST.getDes();
        } else if (SendWayEnums.EMAIL.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.EMAIL.getDes();
        } else if (SendWayEnums.NOTICE.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.NOTICE.getDes();
        } else if (SendWayEnums.TEXT_MSG.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.TEXT_MSG.getDes();
        } else if (SendWayEnums.LOCAL_MSG.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())) {
            return SendWayEnums.LOCAL_MSG.getDes();
        } else if (SendWayEnums.LOCAL_MSG.getCode().equals(caseAdditionalRecordDto.getDecisionSentWay())){
            return SendWayEnums.SENT_REGISTER.getDes();
        }else {
            return "";
        }
    }
}